define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/goods/index',
                    add_url: 'order/goods/add',
                    edit_url: 'order/goods/edit',
                    del_url: 'order/goods/del',
                    multi_url: 'order/goods/multi',
                    table: 'order_goods',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'order_id', title: __('Order_id')},
                        {field: 'order_sn', title: __('Order_sn')},
                        {field: 'goods_id', title: __('Goods_id')},
                        {field: 'goods_sn', title: __('Goods_sn')},
                        {field: 'buy_number', title: __('Buy_number')},
                        {field: 'buy_note', title: __('Buy_note')},
                        {field: 'total_price', title: __('Total_price'), operate:'BETWEEN'},
                        {field: 'created_time', title: __('Created_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'order.id', title: __('Order.id')},
                        {field: 'order.guid', title: __('Order.guid')},
                        {field: 'order.admin_id', title: __('Order.admin_id')},
                        {field: 'order.order_parent_sn', title: __('Order.order_parent_sn')},
                        {field: 'order.order_id', title: __('Order.order_id')},
                        {field: 'order.order_sn', title: __('Order.order_sn')},
                        {field: 'order.order_status', title: __('Order.order_status'), formatter: Table.api.formatter.status},
                        {field: 'order.examine_switch', title: __('Order.examine_switch'), formatter: Table.api.formatter.toggle},
                        {field: 'order.out_trade_no', title: __('Order.out_trade_no')},
                        {field: 'order.pay_sn', title: __('Order.pay_sn')},
                        {field: 'order.pay_status', title: __('Order.pay_status'), formatter: Table.api.formatter.status},
                        {field: 'order.pay_name', title: __('Order.pay_name')},
                        {field: 'order.pay_note', title: __('Order.pay_note')},
                        {field: 'order.pay_scope', title: __('Order.pay_scope')},
                        {field: 'order.buyer_id', title: __('Order.buyer_id')},
                        {field: 'order.buyer_status', title: __('Order.buyer_status'), formatter: Table.api.formatter.status},
                        {field: 'order.buyer_name', title: __('Order.buyer_name')},
                        {field: 'order.buyer_mobile', title: __('Order.buyer_mobile')},
                        {field: 'order.buyer_id_type', title: __('Order.buyer_id_type')},
                        {field: 'order.buyer_id_no', title: __('Order.buyer_id_no')},
                        {field: 'order.ship_sn', title: __('Order.ship_sn')},
                        {field: 'order.ship_status', title: __('Order.ship_status'), formatter: Table.api.formatter.status},
                        {field: 'order.ship_address', title: __('Order.ship_address')},
                        {field: 'order.ship_zipcode', title: __('Order.ship_zipcode')},
                        {field: 'order.ship_code', title: __('Order.ship_code')},
                        {field: 'order.ship_note', title: __('Order.ship_note')},
                        {field: 'order.ship_name', title: __('Order.ship_name')},
                        {field: 'order.ship_oos', title: __('Order.ship_oos')},
                        {field: 'order.receive_name', title: __('Order.receive_name')},
                        {field: 'order.receive_mobile', title: __('Order.receive_mobile')},
                        {field: 'order.goods_fee', title: __('Order.goods_fee'), operate:'BETWEEN'},
                        {field: 'order.goods_tax', title: __('Order.goods_tax'), operate:'BETWEEN'},
                        {field: 'order.ship_fee', title: __('Order.ship_fee'), operate:'BETWEEN'},
                        {field: 'order.discount_fee', title: __('Order.discount_fee'), operate:'BETWEEN'},
                        {field: 'order.order_fee', title: __('Order.order_fee'), operate:'BETWEEN'},
                        {field: 'order.create_time', title: __('Order.create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'order.confirm_time', title: __('Order.confirm_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'order.pay_time', title: __('Order.pay_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'order.ship_time', title: __('Order.ship_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'order.ship_time_end', title: __('Order.ship_time_end')},
                        {field: 'order.currency', title: __('Order.currency')},
                        {field: 'order.order_note', title: __('Order.order_note')},
                        {field: 'goods.id', title: __('Goods.id')},
                        {field: 'goods.goods_id', title: __('Goods.goods_id')},
                        {field: 'goods.guid', title: __('Goods.guid')},
                        {field: 'goods.admin_id', title: __('Goods.admin_id')},
                        {field: 'goods.goods_sn', title: __('Goods.goods_sn')},
                        {field: 'goods.goods_name', title: __('Goods.goods_name')},
                        {field: 'goods.goods_price', title: __('Goods.goods_price')},
                        {field: 'goods.goods_status', title: __('Goods.goods_status')},
                        {field: 'goods.unit_code', title: __('Goods.unit_code')},
                        {field: 'goods.goods_weight', title: __('Goods.goods_weight'), operate:'BETWEEN'},
                        {field: 'goods.net_weight', title: __('Goods.net_weight'), operate:'BETWEEN'},
                        {field: 'goods.brand_name', title: __('Goods.brand_name')},
                        {field: 'goods.bar_code', title: __('Goods.bar_code')},
                        {field: 'goods.record_code', title: __('Goods.record_code')},
                        {field: 'goods.record_hs_code', title: __('Goods.record_hs_code')},
                        {field: 'goods.record_price', title: __('Goods.record_price')},
                        {field: 'goods.record_time', title: __('Goods.record_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'goods.record_status', title: __('Goods.record_status'), formatter: Table.api.formatter.status},
                        {field: 'goods.goods_spec', title: __('Goods.goods_spec')},
                        {field: 'goods.goods_desc', title: __('Goods.goods_desc')},
                        {field: 'goods.created_time', title: __('Goods.created_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'goods.country_code', title: __('Goods.country_code')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});